#ifndef __CP1616_Client_h__
#define __CP1616_Client_h__

typedef union   
{
	struct
	{
		unsigned bRx:1;
	};
	unsigned char AllFlag;
} _CP1616_Client_Flags;        // general flags


#define CP1616_Client_TxByteWithVerify(x) Uart1_VerifySumAddTxByte(x)
#define CP1616_Client_TxByte(x) Uart1_PutChar(x)


#define pCP1616_ClientData 4
#define pCP1616_CommandIndex 2

#ifndef CheckVerify_CP1616_Client
#define CheckVerify_CP1616_Client()	sum=GetVerify_Sum(CP1616_Client_RxList,CP1616_Client_NeedRxCount-2); \
												if(sum==CP1616_Client_RxList[CP1616_Client_NeedRxCount-2])	\
													{sum=1;}\
												else\
													{sum=0;}
#endif

#define CP1616_Client_AddTxHeader()	CP1616_Client_TxByteWithVerify(0x16);	\
						CP1616_Client_TxByteWithVerify(0x16);	

#define CP1616_Client_AddTxEnder()	CP1616_Client_TxByte(sum);	\
						CP1616_Client_TxByte(0x0d);

#ifndef MAX_CP1616_Client_RX
#define MAX_CP1616_Client_RX 50
#endif

extern _CP1616_Client_Flags CP1616_Client_Flags;
extern unsigned char CP1616_Client_RxList[MAX_CP1616_Client_RX];
extern unsigned char CP1616_Client_RxCount;
extern unsigned char CP1616_Client_NeedRxCount;
extern unsigned int CP1616_Client_NoRxTick;

void CP1616_Client_Init(void);
void CP1616_Client_EndProcCommand(void);
void CP1616_Client_ProcRx(unsigned char rx);
void CP1616_Client_SendData(unsigned char CommandIndex,unsigned char* pBuff,unsigned char Count);
void CP1616_Client_SendOK(unsigned char CommandIndex);
void CP1616_Client_SendError(unsigned char CommandIndex);


#endif


